package com.dsr.controller;

import com.dsr.consts.Result;
import com.dsr.consts.e.MangerProperty;
import com.dsr.entity.Manager;
import com.dsr.service.ManagerService;
import com.dsr.util.BasicUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * (Manager)表控制层
 *
 * @author dsr
 * @since 2020-08-25
 */
@Api(tags = "(Manager)表控制层")
@RestController
@RequestMapping("/manager")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    @ApiOperation("更具id获取实体")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "id", required = true)
    })
    @GetMapping("/get/{id}")
    public Result getEntity(@PathVariable String id) {
        return managerService.getEntity(id);
    }

    @ApiOperation("保存操作")
    @ApiParam(name = "manager", value = "实体", required = true)
    @PostMapping("/save")
    public Result save(@RequestBody Manager manager) {
        return managerService.save(manager);
    }

    @ApiOperation("更新操作")
    @ApiParam(name = "manager", value = "实体", required = true)
    @PutMapping("/update")
    public Result update(@RequestBody Manager manager) {
        return managerService.update(manager);
    }

    @ApiOperation("根据id删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id(ps:1,2,3)", required = true)
    })
    @DeleteMapping("/delete")
    public Result delete(@RequestBody String id) {
        return managerService.delete(id);
    }

    @ApiOperation("查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "页", required = true),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页大小", required = true),
    })
    @ApiParam(name = "manager", value = "查询字段", required = true)
    @PostMapping("/list/{page}/{size}")
    public Result query(@PathVariable int page, @PathVariable int size, @RequestBody Manager manager) {
        return managerService.query(page, size, manager);
    }

    @ApiOperation("返回所有")
    @GetMapping("/list")
    public Result list() {
        return managerService.list();
    }

    @ApiOperation("管理员登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "用户名", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true)
    })
    @PostMapping("/login")
    public Result login( @RequestBody Manager manager) {
        return managerService.login(manager.getUserName(),manager.getPassword());
    }
    @ApiOperation("获取管理员信息")
    @GetMapping("/getInfo")
    public Result getInfo( ) {
        return managerService.getEntity(BasicUtil.getToken(MangerProperty.MANGER_ID));
    }

}